package com.life.view;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.TitledBorder;

import com.life.constants.Constants;

public class GenerateConfigurationPanel extends JPanel {

	WidgetRegistry widgetRegistry = WidgetRegistry.getInstance();
	static int frameWidth = 280;
	static int frameHeight = 600;
	
	public static void main(String args[])
	{
		JFrame frame = new JFrame();
		frame.setBounds(0,0,frameWidth+10,600);
		frame.add(new GenerateConfigurationPanel());
		frame.setVisible(true);
	}
	
	JSpinner numberSpinner = null;
	SpinnerNumberModel numberModel = null;
	
	
	public GenerateConfigurationPanel()
	{
		init();
	}
	
	public void init()
	{
		this.setLayout(null);
		TitledBorder generateLifeTitle = new TitledBorder("Create Life");
		
		JPanel generationPanel = new JPanel();
		generationPanel.setBorder(generateLifeTitle);
		generationPanel.setLayout(null);
		generationPanel.setBounds(0,0,280,100);
		this.add(generationPanel);
		
		numberSpinner = new JSpinner();
		numberModel = new SpinnerNumberModel();
		
		numberModel.setMaximum(new Integer(Constants.MAX_GENERATE_LIFE_SIZE));
		numberModel.setMinimum(new Integer(Constants.MIN_GENERATE_LIFE_SIZE));
		numberModel.setValue(new Integer(Constants.GENERATE_LIFE_START));
		numberModel.setStepSize(new Integer(Constants.GENERATE_LIFE_STEP));
		
		numberSpinner.setModel(numberModel);
		
		numberSpinner.setBounds(10,40,100,30);
		generationPanel.add(numberSpinner);
		
		JButton applyButton = new JButton("Create");
		applyButton.setBounds(150,25,95,55);
		
		generationPanel.add(applyButton);
		
		
		TitledBorder eraseLifeTitle = new TitledBorder("Remove Life");
		JPanel eraseLifePanel = new JPanel();
		eraseLifePanel.setBorder(eraseLifeTitle);
		eraseLifePanel.setBounds(0,105,280,100);
		eraseLifePanel.setLayout(null);
		this.add(eraseLifePanel);
		
		JButton clearButton = new JButton("Clear");
		clearButton.setBounds(150,25,95,55);
		eraseLifePanel.add(clearButton);
		
		widgetRegistry.put(Constants.GENERATE_LIFE_APPLY_WIDGET,applyButton);
		widgetRegistry.put(Constants.GENERATE_LIFE_SPINNER_WIDGET,numberSpinner);
		widgetRegistry.put(Constants.ERASE_LIFE_WIDGET,clearButton);
		
	}
}
